package com.javasm.bootdemo.user.service.impl;

import com.javasm.bootdemo.user.entity.WebUser;
import com.javasm.bootdemo.user.dao.WebUserDao;
import com.javasm.bootdemo.user.entity.WebUserInfo;
import com.javasm.bootdemo.user.service.WebUserInfoService;
import com.javasm.bootdemo.user.service.WebUserService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * (WebUser)表服务实现类
 *
 * @author makejava
 * @since 2025-06-26 15:04:25
 */
@Service("webUserService")
public class WebUserServiceImpl implements WebUserService {
    @Resource
    private WebUserDao webUserDao;


    @Resource
    private WebUserInfoService webUserInfoService;

    /**
     * 通过ID查询单条数据
     *
     * @param uid 主键
     * @return 实例对象
     */
    @Override
    public WebUser queryById(Integer uid) {

        return this.webUserDao.queryById(uid);
    }

      /**
     * 新增数据
     *
     * @param webUser 实例对象
     * @return 实例对象
     */
    @Override
    public WebUser insert(WebUser webUser) {
        this.webUserDao.insert(webUser);
        return webUser;
    }

    /**
     * 修改数据
     *
     * @param webUser 实例对象
     * @return 实例对象
     */
    @Override
    public WebUser update(WebUser webUser) {
        this.webUserDao.update(webUser);
        return this.queryById(webUser.getUid());
    }

    /**
     * 通过主键删除数据
     *
     * @param uid 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer uid) {
        return this.webUserDao.deleteById(uid) > 0;
    }

    @Override
    public WebUser queryByUname(String uname) {

       WebUser webUser =   webUserDao.selectByUname(uname);
       if(webUser != null){
           WebUserInfo webUserInfo = webUserInfoService.queryById(webUser.getUid());
           webUser.setWebUserInfo(webUserInfo);

       }




        return webUser;
    }
}
